package com.cuit.xsc.weishare.adapter;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.cuit.xsc.weishare.R;
import com.cuit.xsc.weishare.adapter.WeiboAdapter.WeiboHolder;
import com.cuit.xsc.weishare.model.DirectMessage;
import com.cuit.xsc.weishare.util.TextUtil;
import com.cuit.xsc.weishare.widget.RemoteCacheImageView;

public class PrivateMsgAdapter extends ArrayListAdapter<DirectMessage>
{

	private Context context;

	public PrivateMsgAdapter(Activity context)
	{
		super(context);
		this.context = context;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent)
	{
		
		PrivateMsgHolder holder = null;

		if (null == convertView)
		{

			holder = new PrivateMsgHolder();

			convertView = LayoutInflater.from(context).inflate(R.layout.pivate_msg_item, null);
			
			holder.private_msg_item_head = (RemoteCacheImageView) convertView.findViewById(R.id.private_msg_item_head);
			holder.private_msg_item_uname = (TextView) convertView.findViewById(R.id.private_msg_item_uname);			
			holder.private_msg_item_V =  (ImageView) convertView.findViewById(R.id.private_msg_item_V);			
			holder.private_msg_item_content = (TextView) convertView.findViewById(R.id.private_msg_item_content);			
			holder.private_msg_item_time = (TextView) convertView.findViewById(R.id.private_msg_item_time);			
			
			convertView.setTag(holder);
		}
		else
		{
			holder =  (PrivateMsgHolder) convertView.getTag();
		}
		
		DirectMessage msg = mList.get(position);
		if (msg != null)
		{
			String head = null;
			String name = null;
			//String text = null;
			
			if (msg.getType() == DirectMessage.RECV)
			{
				head = msg.getHead();
				name = msg.getNick();
				
			}
			else if(msg.getType() == DirectMessage.SEND)
			{
				head = msg.getTohead();
				name = msg.getTonick();
			}
			
			
			
			holder.private_msg_item_head.setImageUrl(head, position, mListView);
			holder.private_msg_item_uname.setText(name);
//			holder.private_msg_item_V
			holder.private_msg_item_content.setText(msg.getText());
			holder.private_msg_item_time.setText(TextUtil.formatDate(msg.getTime()));
		}
		return convertView;
	}
	
	
	public class PrivateMsgHolder
	{
		RemoteCacheImageView private_msg_item_head;
		TextView private_msg_item_uname;
		ImageView private_msg_item_V;
		TextView private_msg_item_time;
		TextView private_msg_item_content;
	}

}
